package com.ruoyi.web.controller.resturant;


import com.alibaba.fastjson2.JSON;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.resturant.domain.ResShop;
import com.ruoyi.resturant.service.IResShopService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * 店铺Controller
 *
 * @author Daniel
 * @date 2023-09-27
 */
//@Anonymous
@RestController
@RequestMapping("/api/resturant/shop")
@Api(tags="店铺管理")
public class ResShopController {
    @Autowired
    IResShopService service;
    @Autowired
    RedisCache cache;
    //23201012829-唐明雪
    @ApiOperation("if查询，获取店铺列表")
    @PostMapping("/selectResShopList")
    public AjaxResult selectResShopList(@RequestBody ResShop resShop){

        List<ResShop> resultList = service.selectShopList(resShop);
        for (int i = 0;i<resultList.size();i++){
            String jsonStr = JSON.toJSONString(resultList.get(i));
            int id = resultList.get(i).getId();
//            System.out.println(name);
            cache.setCacheObject(String.valueOf(id),jsonStr,20, TimeUnit.SECONDS);
        }
        return AjaxResult.success(resultList);
    }
    @ApiOperation("when查询，获取店铺列表")
    @PostMapping("/selectResShopList2")
    public AjaxResult selectResShopList2(@RequestBody ResShop resShop){
        return AjaxResult.success(service.selectShopList2(resShop));
    }
    @ApiOperation("测试日志")
    @PostMapping("/selectResShopList3")
//    @Log(title = "获取店铺列表",businessType = BusinessType.OTHER)
    public AjaxResult selectResShopList3(@RequestBody ResShop resShop){
        return AjaxResult.success(service.selectShopList2(resShop));
    }
    @ApiOperation(value = "获取的所有店铺列表")
    @RequestMapping("/queryAll")
    public AjaxResult queryAll(){
        List<ResShop> result = service.queryAll();
        return AjaxResult.success(result);
    }
    @ApiOperation("新增店铺")
    @PostMapping("/addResShop")
    public AjaxResult addResShop(@RequestBody ResShop resShop){
        int result = service.addResShop(resShop);
        return AjaxResult.success(result);
    }
    @ApiOperation("修改信息")
    @PostMapping("/updateResShop")
    public AjaxResult updateResShop( @RequestBody ResShop resShop){
        service.updateResShop(resShop);
        return AjaxResult.success();
    }
    @ApiOperation("删除信息")
    @GetMapping("/deleteResShop")
    public AjaxResult deleteResShop( int id){
        service.deleteResShop(id);
        return AjaxResult.success();
    }
    // 尝试存入一个复杂类型
    @ApiOperation(value = "根据店铺id，获取redis的数据")
    @GetMapping("/getResShop")
    public AjaxResult getResShop(int id){
        return AjaxResult.success();
    }
    // 根据店铺姓名查询
    @ApiOperation("根据姓名查询店铺")
    @GetMapping("/GetResShopByName")
    public AjaxResult GetResShopByName(String name){
        return AjaxResult.success(service.queryResShopByname(name));
    }
//尝试存入一个复杂类型
//    @ApiOperation(value = "根据店铺id，获取redis的数据")
//    @GetMapping("/getResShop")
//    public AjaxResult getResShop(int id){
//    return AjaxResult.success();
//    }





//    @Autowired
//    private IResShopService resShopService;
//
//    /**
//     * 查询店铺列表
//     */
//    @ApiOperation("查询店铺列表")
//    @ApiImplicitParam(name = "name", value = "店铺名称",
//            dataType = "string", dataTypeClass = String.class)
//    @GetMapping("/list")
//    public AjaxResult list(@RequestParam(value = "name", required = false) String shopName) {
//        List<ResShop> list = resShopService.selectResShopByParam(shopName);
//        return AjaxResult.success(list);
//    }
//
//    /**
//     * 获取店铺详细信息
//     */
//    @ApiOperation(value = "获取店铺详细信息", notes = "TODO：取得某个店铺的详细信息")
//    @ApiImplicitParam(name = "id", value = "店铺ID",
//            required = true, dataType = "long", paramType = "path",
//            dataTypeClass = Long.class)
//    @GetMapping(value = "/{id}")
//    public AjaxResult getInfo(@PathVariable("id") Long id) {
//        return AjaxResult.success(resShopService.selectResShopById(id));
//    }
//
//    /**
//     * 新增店铺
//     */
//    @ApiOperation("新增店铺")
//    @PostMapping
//    public AjaxResult add(@RequestBody ResShop resShop) {
//        return AjaxResult.success(resShopService.insertResShop(resShop));
//    }
//
//    /**
//     * 修改店铺
//     */
//    @ApiOperation("修改店铺")
//    @PutMapping
//    public AjaxResult edit(@RequestBody ResShop resShop) {
//        return AjaxResult.success(resShopService.updateResShop(resShop));
//    }
//
//    /**
//     * 删除店铺
//     */
//    @ApiOperation("删除店铺")
//    @ApiImplicitParam(name = "id", value = "店铺ID", required = true, dataType = "long", paramType = "path", dataTypeClass = Long.class)
//    @DeleteMapping("/{id}")
//    public AjaxResult remove(@PathVariable Long id) {
//        return AjaxResult.success(resShopService.deleteResShopById(id));
//    }
}